###字典

#创建字典
person = {
    "name":"Ming",
    "age":20,
    "sex":"male",
    "courses":['java','go','python']
}
dic = dict(a=100,b=500,c=('east','west','south','north'))
print(type(person))     #<class 'dict'>

#获取字典中指定键的值
value1 = person.get('name')     
value2 = dic['a']
print(value1,value2)    #Ming,100

#获取字典中键值对的数量
length = len(person)
print(length)           #4

#删除并返回指定键的值
del_value = person.pop('sex')
print(del_value)    #male
print(person)       #{'name': 'Ming', 'age': 20, 'courses': ['java', 'go', 'python']}

#判断指定键是否存在于字典
flag = 'sex' in person
print(flag)         #False

#遍历字典的键
for key in dic.keys():
    print(key)              #a b c

#遍历字典的值
for value in dic.values():
    print(value)            # 100 500 ('east', 'west', 'south', 'north')

#遍历字典
for key,value in dic.items():
    print(f"{key}:{value}")     #a:100 b:500 c:('east', 'west', 'south', 'north')

#清空字典
dic.clear()

#删除字典
del dic
# print(dic)

